Skip to content

Conversation

@AntonioVentilii
Copy link
Contributor

I would like to propose a new rule prefer-called-once that enforces the use of toBeCalledTimes(1) or toHaveBeenCalledTimes(1) over toBeCalledOnce() or toHaveBeenCalledOnce().

Examples of incorrect code for this rule:

test('foo', () => {
    const mock = vi.fn()
    mock('foo')
    expect(mock).toBeCalledOnce()
    expect(mock).toHaveBeenCalledOnce()
})

Examples of correct code for this rule:

test('foo', () => {
  const mock = vi.fn()
  mock('foo')
  expect(mock).toBeCalledTimes(1)
  expect(mock).toHaveBeenCalledTimes(1)
})

@AntonioVentilii AntonioVentilii changed the title feat: New rule prefer-called-times feat: New rule prefer-called-times Jun 20, 2025
@veritem
Copy link
Member

veritem commented Jun 23, 2025

Totally messed up this pr with documentation tool bug triage. That is on me, your work looks great! Thank you!

@AntonioVentilii
Copy link
Contributor Author

Thank you @veritem ! For taking care of it

@veritem
Copy link
Member

veritem commented Jun 26, 2025

hey, i made so many experiments in this pr than i should have, sorry about that. i have opened a new pr that includes your work in #733. Once i merge it, it should be released.

@veritem veritem closed this Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants